import { IModelAdapter } from "./IModelAdapter";

/**
 * 适配器工厂类
 * 用于管理和创建不同类型的适配器
 */
export class ModelAdapterFactory {
    private static adapters: Map<string, new (apiKey: string, baseURL?: string) => IModelAdapter> = new Map();

    /**
     * 注册适配器类
     */
    static registerAdapter(name: string, adapterClass: new (apiKey: string, baseURL?: string) => IModelAdapter): void {
        this.adapters.set(name.toLowerCase(), adapterClass);
    }

    /**
     * 创建适配器实例
     */
    static createAdapter(name: string, apiKey: string, baseURL?: string): IModelAdapter {
        const AdapterClass = this.adapters.get(name.toLowerCase());
        if (!AdapterClass) {
            throw new Error(`Adapter '${name}' not found. Available adapters: ${Array.from(this.adapters.keys()).join(', ')}`);
        }
        return new AdapterClass(apiKey, baseURL);
    }

    /**
     * 获取所有已注册的适配器名称
     */
    static getAvailableAdapters(): string[] {
        return Array.from(this.adapters.keys());
    }

    /**
     * 检查适配器是否已注册
     */
    static hasAdapter(name: string): boolean {
        return this.adapters.has(name.toLowerCase());
    }
}